//package com.wzf.greattruth.zookeeper.operator;
//
//import java.util.List;
//
//import org.apache.commons.lang3.StringUtils;
//import org.apache.zookeeper.CreateMode;
//import org.apache.zookeeper.KeeperException;
//import org.apache.zookeeper.ZooKeeper;
//import org.apache.zookeeper.data.ACL;
//
//import com.wzf.greattruth.zookeeper.ZookeeperManager;
//import com.wzf.greattruth.zookeeper.dto.CreateNodeParam;
//
//public class ZooKeeperCreateNodeOperator extends ZooKeeperOperator<CreateNodeParam, String> {
//
//    /**
//     * 创建dir的Operator
//     */
//    private ZooKeeperCreateParentDirOperator createDirNodeOperator;
//
//    public ZooKeeperCreateNodeOperator(ZooKeeper zookeeper, String path, byte[] datas, CreateMode mode) {
//        super(zookeeper, path, datas, mode);
//        createDirNodeOperator = new ZooKeeperCreateParentDirOperator(zookeeper, path, datas, CreateMode.PERSISTENT);
//    }
//
//    public ZooKeeperCreateNodeOperator(ZooKeeper zookeeper, String path, CreateMode mode) {
//        this(zookeeper, path, null, mode);
//    }
//
//    @Override
//    public synchronized String doOperate(CreateNodeParam param) throws KeeperException, InterruptedException {
//
//        Boolean createParentDirResult = createDirNodeOperator.operate();
//        if (createParentDirResult == null || !createParentDirResult) {
//            return null;
//        }
//
//        ZooKeeper zookeeper = getZookeeper();
//        String dir = getDir();
//        CreateMode mode = getMode();
//        List<ACL> acl = getAcl();
//        
//        String currentNodeId = param.getNodeId();
//        byte[] datas = param.getDatas();
//
//        if (StringUtils.isBlank(currentNodeId)) {
//            String ephemeralDir = ZookeeperManager.getInstance().fillDirWithSeparator(dir);
//            // 如果当前临时node节点不存在，则创建一个
//            String nodePath = zookeeper.create(ephemeralDir, datas, acl, mode);
//            
//            currentNodeId = ZookeeperManager.getInstance().getNodeId(nodePath, ephemeralDir);
//
//            System.err.println(Thread.currentThread().getName() + "   createNode id=" + currentNodeId);
//        }
//        return currentNodeId;
//    }
//
//}
